<?php
class UserForm extends CFormModel
{
    public $login;
    public $password;
    public $rememberMe=false;
	
	private $_identity;
	
	public function rules()
    {
        return array(
            array('login, password', 'required'),
            array('rememberMe', 'boolean'),
            array('password', 'authenticate'),
        );
    }
	
	public function authenticate($attribute, $params)
    {
        $this->_identity = new UserIdentity($this->login, $this->password);
        if(!$this->_identity->authenticate())
		{
            $this->addError('password', 'Неправильное имя пользователя или пароль.');
		}
		else
		{
			if($this->rememberMe)
			{
				Yii::app()->user->login($this->_identity, 3600*24*7);
			}
			else
			{
				Yii::app()->user->login($this->_identity);
			}
		}
    }
}